package org.millioncall.yueyoga.admin.action;

import httl.util.DateUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.millioncall.openplatform.common.Pager;
import org.millioncall.openplatform.common.PaginatedList;
import org.millioncall.openplatform.util.DateTimeUtils;
import org.millioncall.openplatform.util.WebAppUtils;
import org.millioncall.yueyoga.admin.export.AbstractExcelExportTemplate;
import org.millioncall.yueyoga.admin.export.TaskExportTemplate;
import org.millioncall.yueyoga.admin.model.AviatorExpression;
import org.millioncall.yueyoga.admin.model.Group;
import org.millioncall.yueyoga.admin.model.GroupUserModel;
import org.millioncall.yueyoga.admin.model.HomePageTaskRecord;
import org.millioncall.yueyoga.admin.model.Member;
import org.millioncall.yueyoga.admin.model.Status;
import org.millioncall.yueyoga.admin.model.Task;
import org.millioncall.yueyoga.admin.model.User;
import org.millioncall.yueyoga.admin.service.GroupsService;
import org.millioncall.yueyoga.admin.service.MemberService;
import org.millioncall.yueyoga.admin.service.StatusService;
import org.millioncall.yueyoga.admin.service.TaskService;
import org.millioncall.yueyoga.admin.service.UserDetailService;
import org.millioncall.yueyoga.admin.service.UserService;
import org.millioncall.yueyoga.common.GlobalConstants;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

/**
 * @author lisj Mar 29, 2014 8:26:58 AM
 */
@Controller
public class TaskAction extends BaseAction {
	private TaskService taskService;
	private UserService userService;
	private StatusService statusService;
	private MemberService memberService;
	private GroupsService groupsService;
	private UserDetailService userDetailService;

	private static final String TASK_SEARCH = "task_search";
	private static final String TASK_ADD = "task_add";
	private static final String TASK_EDIT = "task_edit";
	private static final String TASK_DETAIL = "task_detail";
	
	/** 高级搜索任务 */
	@RequestMapping(value = "/ajaxAdvSearchTasks.jhtml")
	public void advSearchMember(HttpServletRequest request,
			HttpServletResponse response, ModelMap model) {
		String strLimit = request.getParameter("limit");

		String exp = request.getParameter("expression");
		String expType = request.getParameter("expType");

		String msg = "";

		int limit = Integer.MAX_VALUE;

		try {
			limit = Integer.parseInt(strLimit);
		} catch (NumberFormatException e) {
			limit = Integer.MAX_VALUE;
		}

		if (StringUtils.isBlank(exp)) {
			msg = "{'success':false, 'msg':'表达式不能为空！'}";
			WebAppUtils.ajaxResponse(response, msg);
			return;
		}

		if (StringUtils.isBlank(expType)) {
			msg = "{'success':false, 'msg':'表达式类型不能为空！'}";
			WebAppUtils.ajaxResponse(response, msg);
			return;
		}

		// 用于过滤会员的条件map
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("hallcode", this.getUser(request).getOrganizationId());

		// 条件表达式
		// 在此组装条件表达式
		AviatorExpression expression = new AviatorExpression();
		expression.setExpression(exp);
		// 条件表达式的map
		Map<String, Object> aviatorParams = new HashMap<String, Object>();
		aviatorParams.put(GlobalConstants.RESULT_ROW_MODEL_KEY, expType);

		List<HomePageTaskRecord> tasks = this.taskService.getAllTasksWithAviator(params, expression, aviatorParams, limit);

		if (tasks.size() > 0) {
			String json = JSON.toJSONStringWithDateFormat(tasks, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteDateUseDateFormat);
			msg = "{'success':true, 'total':'" + tasks.size() + "', 'items':"
					+ json + "}";
		} else {
			msg = "{'success':true, 'total':'0', 'items':''}";
		}

		WebAppUtils.ajaxResponse(response, msg);
	}

	// 查询任务信息
	@RequestMapping(value = "/searchTasks.jhtml")
	public String findTasksByConditions(String taskName, String subStatusId,
			String memberId, String creatorId, String resporId,
			String taskStatus, String memberStatus, String beginExpiryDate,
			String endExpiryDate, String aboutToExpiry, String pageNo,
			String pageSize, HttpServletRequest request, ModelMap model) {
		this.initFrontHeader(request, model);
		User user = this.getUser(request);
		int start = 0;
		int limit = 10;

		String display = request.getParameter("display");
		if ("block".equals(display)) {
			model.put("display", display);
		}
		Map<String, Object> map = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(pageSize)) {
			limit = Integer.parseInt(pageSize);
		}
		if (StringUtils.isNotBlank(pageNo)) {
			start = (Integer.parseInt(pageNo) - 1) * limit;
		}

		if (StringUtils.isNotBlank(taskName)) {
			map.put("taskName", taskName);
			model.put("taskName", taskName);
		}
		if (StringUtils.isNotBlank(subStatusId)) {
			map.put("subStatusId", subStatusId);
			model.put("subStatusId", subStatusId);
		}
		if (StringUtils.isNotBlank(creatorId)) {
			map.put("creatorId", creatorId);
			model.put("creatorId", creatorId);

		}
		if (StringUtils.isNotBlank(resporId)) {
			map.put("resporId", resporId);
			model.put("resporId", resporId);
		}
		if (StringUtils.isNotBlank(taskStatus)) {
			map.put("taskStatus", taskStatus);
			model.put("taskStatus", taskStatus);
		}
		if (StringUtils.isNotBlank(memberId)) {
			map.put("memberId", memberId);
			model.put("memberId", memberId);
		}
		if (StringUtils.isNotBlank(memberStatus)) {
			map.put("memberStatus", memberStatus);
			model.put("memberStatus", memberStatus);
		}
		if (StringUtils.isNotBlank(beginExpiryDate)) {
			map.put("beginExpiryDate", beginExpiryDate);
			model.put("beginExpiryDate", beginExpiryDate);
		}
		if (StringUtils.isNotBlank(endExpiryDate)) {
			map.put("endExpiryDate", endExpiryDate);
			model.put("endExpiryDate", endExpiryDate);
		}
		// 查询过期的任务
		if (StringUtils.isNotBlank(aboutToExpiry) && aboutToExpiry.equals("1")) {
			map.put("expiryDate",
					DateTimeUtils.getInstance()
							.format(new Date(), "yyyy-MM-dd"));
			map.put("aboutToExpiry", "1");
			map.put("state", "1");
			map.put("hallcode", user.getOrganizationId());
			model.put("aboutToExpiry", "1");
		}
		model.put("taskTypes", statusService.findByType(4));// 根据类型查询父类状态(工作安排)
		List<Integer> groupIds = new ArrayList<Integer>();
		for (Group group : this.getUser(request).getGroups()) {
			groupIds.add(group.getId());
		}

		Map<String, Object> map1 = new HashMap<String, Object>();
		map1.put("key", "organizationId");
		map1.put("value", user.getOrganizationId());
		map1.put("groups", groupIds);
		map1.put("hallcode", this.getUser(request).getOrganizationId());
		model.put("members", memberService.findMemberByProperty(map1));// 查询会员
		model.put("memberTypes", statusService.findByType(1));// 会员状态
		// 查询创建人
		List<User> users = this.userService.findTaskUser();
		model.put("user", users);
		// 查询负责人

		List<GroupUserModel> respors = this.userService.findUsersByGroupId("4",
				user.getOrganizationId());
		model.put("responsibles", respors);

		map.put("groups", groupIds);
		map.put("hallcode", this.getUser(request).getOrganizationId());
		PaginatedList<HomePageTaskRecord> pl = null;
		if ("block".equals(display)) {
			pl = taskService.findTasksByCdts(map, start, limit);
		}
		model.put("pl", pl);
		return TASK_SEARCH;
	}

	// 导出任务
	@RequestMapping(value = "/exportTaskInfo.jhtml")
	public void exportTaskInfo(String taskName, String subStatusId,
			String memberId, String creatorId, String resporId,
			String taskStatus, String memberStatus, String beginExpiryDate,
			String endExpiryDate, String aboutToExpiry, String pageNo,
			String pageSize, HttpServletRequest request,
			HttpServletResponse response, ModelMap model) {
		this.initFrontHeader(request, model);
		int start = 0;
		int limit = Integer.MAX_VALUE;
		Map<String, Object> map = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(pageSize)) {
			limit = Integer.parseInt(pageSize);
		}
		if (StringUtils.isNotBlank(pageNo)) {
			start = (Integer.parseInt(pageNo) - 1) * limit;
		}

		if (StringUtils.isNotBlank(taskName)) {
			map.put("taskName", taskName);
		}
		if (StringUtils.isNotBlank(subStatusId)) {
			map.put("subStatusId", subStatusId);
		}
		if (StringUtils.isNotBlank(creatorId)) {
			map.put("creatorId", creatorId);
		}
		if (StringUtils.isNotBlank(resporId)) {
			map.put("resporId", resporId);
		}
		if (StringUtils.isNotBlank(taskStatus)) {
			map.put("taskStatus", taskStatus);
		}
		if (StringUtils.isNotBlank(memberId)) {
			map.put("memberId", memberId);
		}
		if (StringUtils.isNotBlank(memberStatus)) {
			map.put("memberStatus", memberStatus);
		}
		if (StringUtils.isNotBlank(beginExpiryDate)) {
			map.put("beginExpiryDate", beginExpiryDate);
		}
		if (StringUtils.isNotBlank(endExpiryDate)) {
			map.put("endExpiryDate", endExpiryDate);
		}

		List<Integer> groupIds = new ArrayList<Integer>();
		for (Group group : this.getUser(request).getGroups()) {
			groupIds.add(group.getId());
		}
		map.put("groups", groupIds);
		map.put("hallcode", this.getUser(request).getOrganizationId());
		PaginatedList<HomePageTaskRecord> pl = taskService.findTasksByCdts(map,
				start, limit);
		TaskExportTemplate template = new TaskExportTemplate(pl);

		response.setContentType(AbstractExcelExportTemplate.EXCEL_TYPE);
		AbstractExcelExportTemplate.setFileDownloadHeader(request, response,
				"任务信息表.xlsx");
		try {
			template.doExport(response.getOutputStream());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	// 进入任务添加页面
	@RequestMapping(value = "/toAddTask.jhtml")
	public String toAddTask(String memberId, ModelMap map,
			HttpServletRequest request) {
		super.initFrontHeader(request, map);

		User user = this.getUser(request);
		map.put("taskTypes", statusService.findByType(4));// 根据类型查询父类状态

		List<Integer> groupIds = new ArrayList<Integer>();
		for (Group group : this.getUser(request).getGroups()) {
			groupIds.add(group.getId());
		}

		Map<String, Object> map1 = new HashMap<String, Object>();
		map1.put("key", "organizationId");
		map1.put("value", user.getOrganizationId());
		map1.put("groups", groupIds);
		map1.put("hallcode", this.getUser(request).getOrganizationId());
		map.put("members", memberService.findMemberByProperty(map1));
		map.put("groups", groupsService.findGroupsByOrganizationId(user
				.getOrganizationId()));
		// 负责人
		map.put("responsibles",
				userService.findUsersByGroupId("4", user.getOrganizationId()));

		Map<String, Object> map2 = new HashMap<String, Object>();
		map2.put("groups", groupIds);
		if (StringUtils.isNotBlank(memberId)) {
			map2.put("id", Integer.valueOf(memberId));
		}
		map2.put("hallcode", this.getUser(request).getOrganizationId());
		Member member = memberService.findById(map2);
		if (StringUtils.isNotBlank(memberId)) {
			map.put("memberInfo", member);
		}

		map.put("resporsId", this.getUser(request).getId());

		return TASK_ADD;
	}

	// 进入任务修改页面
	@RequestMapping(value = "/toEditTask.jhtml")
	public String toEditTask(HttpServletRequest request, String taskId,
			ModelMap map) {

		super.initFrontHeader(request, map);
		User user = this.getUser(request);
		map.put("taskTypes", statusService.findByType(4));// 根据类型查询父类状态
		// 负责人
		map.put("responsibles",
				userService.findUsersByGroupId("4", user.getOrganizationId()));
		List<Integer> groupIds = new ArrayList<Integer>();
		for (Group group : this.getUser(request).getGroups()) {
			groupIds.add(group.getId());
		}
		map.put("groups", groupIds);
		map.put("taskId", taskId);
		map.put("hallcode", this.getUser(request).getOrganizationId());
		Task task = taskService.findTaskRelatedInfoById(map);
		map.put("task", task);
		return TASK_EDIT;
	}

	// 进入任务修改页面
	@RequestMapping(value = "/toViewTask.jhtml")
	public String toViewTask(HttpServletRequest request, String taskId,
			ModelMap map) {
		super.initFrontHeader(request, map);
		User user = this.getUser(request);
		map.put("taskTypes", statusService.findByType(4));// 根据类型查询父类状态
		// 负责人
		map.put("responsibles",
				userService.findUsersByGroupId("4", user.getOrganizationId()));
		List<Integer> groupIds = new ArrayList<Integer>();
		for (Group group : this.getUser(request).getGroups()) {
			groupIds.add(group.getId());
		}
		map.put("groups", groupIds);
		map.put("taskId", taskId);
		map.put("hallcode", this.getUser(request).getOrganizationId());
		Task task = taskService.findTaskRelatedInfoById(map);
		map.put("task", task);
		return "task_mingxi";
	}

	// 添加修改任务
	@RequestMapping(value = "/addTask.jhtml")
	public String updateTask(String taskId, String name, Integer subStatusId,
			String gpsId, String memberId, String resporId, String expirydate,
			String remarks, String type, String state,
			HttpServletRequest request, HttpServletResponse response,
			ModelMap model) {
		super.initFrontHeader(request, model);
		String msg = null;
		User user = this.getUser(request);
		Task task = new Task();
		task.setOrganizationId(user.getOrganizationId());
		if (StringUtils.isNotBlank(taskId)) {
			List<Integer> groupIds = new ArrayList<Integer>();
			for (Group group : this.getUser(request).getGroups()) {
				groupIds.add(group.getId());
			}
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("groups", groupIds);
			map.put("taskId", taskId);
			map.put("hallcode", this.getUser(request).getOrganizationId());
			task = taskService.findTaskById(map);
		} else {
			task.setUserId(this.getUser(request).getId());
		}
		task.setUser(user);
		if (subStatusId != null) {
			task.setSubStatusId(subStatusId);
			Status st = statusService.findById(subStatusId);
			model.put("gongzuo", st.getName());
		}
		if (StringUtils.isNotBlank(name)) {
			task.setName(name);
		}
		DateTimeUtils dtu = DateTimeUtils.getInstance();
		if (StringUtils.isNotBlank(expirydate)) {
			task.setExpirydate(DateUtils.parse(expirydate, "yyyy-MM-dd"));
			Date date = dtu.addDay(task.getExpirydate(), 1);
			if (date.before(new Date())) {
				// 提示到期时间不能早于今天
				msg = "dqsjtx";
				model.put("msg", msg);
				model.put("taskName", name);
				model.put("remarks", remarks);
				if (StringUtils.isNotBlank(taskId)) {
					return "redirect:toEditTask.jhtml?taskId=" + taskId;
				} else {
					return "redirect:toAddTask.jhtml";
				}
			}
		}
		// --负责人
		if (StringUtils.isNotBlank(resporId)) {
			task.setResporId(resporId);
		}
		if (StringUtils.isNotBlank(memberId)) {
			task.setMemberId(Integer.valueOf(memberId));
		}
		if (StringUtils.isNotBlank(gpsId)) {
			task.setGroupsId(gpsId);
		}
		if (StringUtils.isNotBlank(remarks)) {
			task.setRemarks(remarks);
		}
		if (StringUtils.isNotBlank(type)) {
			task.setType(Integer.valueOf(type));
		}
		// 状态修改
		if (StringUtils.isNotBlank(state)) {
			task.setState(Integer.valueOf(state));
		}
		if (StringUtils.isBlank(taskId)) {
			if (taskService.save(task)) {
				msg = "ats";
			} else {
				msg = "ate";
			}
			if(task.getType()==2){
				return "redirect:searchTasks.jhtml";
			}
		} else {
			if (taskService.update(task)) {
				msg = "ets";
			} else {
				msg = "ete";
			}
		}
		model.put("msg", msg);
		return "redirect:toMemberTask.jhtml?id=" + memberId;
	}

	// 根据会员查询会员任务
	@RequestMapping(value = "/toMemberTask.jhtml")
	public String findTaskByMemberId(String id, String pageNo, String pageSize,
			String fjxpageNo, String fjxpageSize, HttpServletRequest request,
			ModelMap model) {
		super.initFrontHeader(request, model);
		Map<String, Object> map = new HashMap<String, Object>();
		int start = 0;
		int limit = 6;
		int fjxstart = 0;
		int fjxlimit = 6;
		if (StringUtils.isNotBlank(pageSize)) {
			limit = Integer.parseInt(pageSize);
		}
		if (StringUtils.isNotBlank(pageNo)) {
			start = (Integer.parseInt(pageNo) - 1) * limit;
		}

		if (StringUtils.isNotBlank(fjxpageSize)) {
			limit = Integer.parseInt(fjxpageSize);
		}
		if (StringUtils.isNotBlank(fjxpageNo)) {
			fjxstart = (Integer.parseInt(fjxpageNo) - 1) * limit;
		}
		User user = this.getUser(request);
		map.put("hallCode", user.getOrganizationId());
		// --会员编号不为空
		if (StringUtils.isNotBlank(id)) {
			map.put("memberId", id);
			// 正在进行的任务
			map.put("taskState", "1");
			List<Integer> groupIds = new ArrayList<Integer>();
			for (Group group : this.getUser(request).getGroups()) {
				groupIds.add(group.getId());
			}
			map.put("groups", groupIds);
			map.put("hallcode", this.getUser(request).getOrganizationId());
			PaginatedList<HomePageTaskRecord> oningTasks = taskService
					.findTasksByState(map, start, limit);
			model.put("oningTasks", oningTasks);
			Pager pager = oningTasks.getPager();
			model.put("jxzPageNo", pager.getPageNo());
			model.put("jxzPrevPageNo", pager.getPrevPageNo());
			model.put("jxzNextPageNo", pager.getNextPageNo());
			model.put("jxzTotalPages", pager.getCountOfTotalPages());
			model.put("jxzTotalResults", pager.getCountOfTotalResults());
			// 飞进行ing的任务
			map.put("taskState", "20");
			PaginatedList<HomePageTaskRecord> finishTasks = taskService
					.findTasksByState(map, fjxstart, fjxlimit);
			model.put("finishTasks", finishTasks);

			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("groups", groupIds);
			map1.put("id", Integer.valueOf(id));
			map1.put("hallcode", this.getUser(request).getOrganizationId());
			Member member = memberService.findById(map1);
			model.put("member", member);
			// 会员状态
			List<Status> status = statusService.findByType(1);// 根据类型查询父类状态
			model.put("memberStatus", status);
			if (member.getSubstatus() != null
					&& !member.getSubstatus().equals("")) {
				Status stat = statusService.findByCode(member.getSubstatus());
				model.put("statu", stat);
				status = statusService.findByParentCode(stat.getParentcode());
				model.put("subStatuses", status);
				stat = statusService.findByCode(stat.getParentcode());
				model.put("parentStatu", stat);
			}
		}
		// 查询负责人
		List<GroupUserModel> respors = this.userService.findUsersByGroupId("4",
				user.getOrganizationId());
		model.put("respors", respors);
		model.put("memberId", id);
		model.put("resporsId", this.getUser(request).getId());

		return TASK_DETAIL;
	}

	// 根据id对任务进行删除操作
	@RequestMapping(value = "/deleteTasksByIds.jhtml")
	public void deleteTasksByIds(String ids, HttpServletResponse response) {
		String msg = null;
		if (StringUtils.isBlank(ids)) {
			msg = "false";
		} else {
			if (taskService.deleteByIds(ids.split(","))) {
				msg = "true";
			} else {
				msg = "false";
			}
		}
		WebAppUtils.ajaxResponse(response, msg);
	}

	/**
	 * ajax获取消费记录
	 * 
	 * @param request
	 * @param response
	 * @param model
	 */
	@RequestMapping(value = "/ajaxGetXxzTaskList.jhtml", method = RequestMethod.POST)
	public void ajaxGetXxzTaskList(String memberId, HttpServletRequest request,
			HttpServletResponse response, ModelMap model, Integer pageNo,
			Integer pageSize) {
		int start = 0;
		int limit = 10;

		if (pageSize != null) {
			limit = pageSize;
		}

		if (pageNo != null) {
			start = (pageNo - 1) * limit;
		}

		Map<String, Object> params = new HashMap<String, Object>();
		List<Integer> groupIds = new ArrayList<Integer>();
		for (Group group : this.getUser(request).getGroups()) {
			groupIds.add(group.getId());
		}
		params.put("memberId", memberId);
		params.put("groups", groupIds);
		params.put("type", "1");
		params.put("hallcode", this.getUser(request).getOrganizationId());
		PaginatedList<HomePageTaskRecord> xxzTaskList = taskService
				.findTasksByState(params, start, limit);
		Pager pager = xxzTaskList.getPager();

		String xxzItems = JSON.toJSONString(xxzTaskList);
		String json = "{'success':true,totalPages:"
				+ pager.getCountOfTotalPages() + ",totalItems:"
				+ pager.getCountOfTotalResults() + ",pageNo:"
				+ pager.getPageNo() + ",pageSize:" + pager.getPageSize()
				+ ",prevPageNo:" + pager.getPrevPageNo() + ",nextPageNo:"
				+ pager.getNextPageNo() + ",items:" + xxzItems + "}";
		WebAppUtils.ajaxResponse(response, json);
	}

	/**
	 * 获取已完成的任务和已经取消的任务
	 * 
	 * @param request
	 * @param response
	 * @param model
	 * @param pageNo
	 * @param pageSize
	 */
	@RequestMapping(value = "/ajaxGetfjxTaskList.jhtml", method = RequestMethod.POST)
	public void ajaxGetfjxTaskList(String memberId, HttpServletRequest request,
			HttpServletResponse response, ModelMap model, Integer pageNo,
			Integer pageSize) {
		int start = 0;
		int limit = 10;

		if (pageSize != null) {
			limit = pageSize;
		}

		if (pageNo != null) {
			start = (pageNo - 1) * limit;
		}

		Map<String, Object> params = new HashMap<String, Object>();
		List<Integer> groupIds = new ArrayList<Integer>();
		for (Group group : this.getUser(request).getGroups()) {
			groupIds.add(group.getId());
		}
		params.put("memberId", memberId);
		params.put("groups", groupIds);
		params.put("type", "20");
		params.put("hallcode", this.getUser(request).getOrganizationId());
		PaginatedList<HomePageTaskRecord> fjxTaskList = taskService
				.findTasksByState(params, start, limit);
		Pager pager = fjxTaskList.getPager();

		String fxxItems = JSON.toJSONString(fjxTaskList);
		String json = "{'success':true,totalPages:"
				+ pager.getCountOfTotalPages() + ",totalItems:"
				+ pager.getCountOfTotalResults() + ",pageNo:"
				+ pager.getPageNo() + ",pageSize:" + pager.getPageSize()
				+ ",prevPageNo:" + pager.getPrevPageNo() + ",nextPageNo:"
				+ pager.getNextPageNo() + ",items:" + fxxItems + "}";
		WebAppUtils.ajaxResponse(response, json);
	}

	// 根据taskId对任务进行修改操作
	@RequestMapping(value = "/updateTaskByTaskId.jhtml")
	public void updateTaskInfoByTaskId(String taskId, String memberId,
			String state, String subStatus, HttpServletRequest request,
			HttpServletResponse response, Map<String, Object> map) {
		String msg = null;
		if (StringUtils.isNotBlank(taskId) && StringUtils.isNotBlank(state)) {
			Task task = new Task();
			Date date = new Date();
			task.setId(Integer.valueOf(taskId));
			task.setExecutetime(date);
			task.setState(Integer.valueOf(state));
			if (StringUtils.isNotBlank(state) && "2".equals(state.trim())) {
				// 完成时间设置为当前时间
				task.setFinishtime(date);
			}
			Member member = null;
			if (StringUtils.isNotBlank(memberId)) {
				Map<String, Object> map1 = new HashMap<String, Object>();
				List<Integer> groupIds = new ArrayList<Integer>();
				for (Group group : this.getUser(request).getGroups()) {
					groupIds.add(group.getId());
				}
				map1.put("groups", groupIds);
				map1.put("id", Integer.valueOf(memberId));
				map1.put("hallcode", this.getUser(request).getOrganizationId());
				member = memberService.findById(map1);
				if(StringUtils.isNotBlank(subStatus)){
					member.setSubstatus(subStatus);
				}
				memberService.updateMember(member);
			}
			if (taskService.update(task)) {
				msg = "修改成功!";
			} else {
				msg = "修改失败!";
			}
		}
		map.put("msg", msg);
		WebAppUtils.ajaxResponse(response, msg);
	}

	public TaskService getTaskService() {
		return taskService;
	}

	public void setTaskService(TaskService taskService) {
		this.taskService = taskService;
	}

	public StatusService getStatusService() {
		return statusService;
	}

	public void setStatusService(StatusService statusService) {
		this.statusService = statusService;
	}

	public MemberService getMemberService() {
		return memberService;
	}

	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}

	public GroupsService getGroupsService() {
		return groupsService;
	}

	public void setGroupsService(GroupsService groupsService) {
		this.groupsService = groupsService;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public UserDetailService getUserDetailService() {
		return userDetailService;
	}

	public void setUserDetailService(UserDetailService userDetailService) {
		this.userDetailService = userDetailService;
	}
}
